package com.xiaowen.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaowen.project.entity.Project;
import com.xiaowen.project.mapper.ProjectMapper;
import com.xiaowen.project.service.ProjectService;
import com.xiaowen.tool.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 项目表 服务实现类
 * </p>
 *
 * @author yf-wenhao
 * @since 2024-09-18
 */
@Service
public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> implements ProjectService {

    @Autowired
    private ProjectMapper projectMapper;

    @Override
    public Page<Project> selectByPage(long current, long size,Project project) {
        Page<Project> page = new Page<>(current, size);
        QueryWrapper<Project> queryWrapper = new QueryWrapper<>();
        queryWrapper.setEntity(project);
        return projectMapper.selectPage(page, queryWrapper);
    }

    @Override
    public void deleteById(Integer id) {
        Project project = projectMapper.selectById(id);
        if (null == project) {
            return;
        }
        project.setDeleteFlag(true);
        projectMapper.updateById(project);
    }

    @Override
    public void add(Project project) {
        project.setUserId(UserContext.getUser().getId());
        projectMapper.insert(project);
    }
}
